app.controller("reimburseAdd",function($scope,$http, $stateParams,get,post,$rootScope,Md5,$state){
	//取消
	$scope.rement=function(){
		$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
	}
	$scope.selects=function(){
		//科目
		get.list("dictionary/subjectDic").then(function(e){
				$scope.subjectDic = e
					//专业
			})
		//付款类型
		get.list("dictionary/paymentDic").then(function(e){
				$scope.paymentDic = e
			})
		//经办人
		get.list("dictionary/staff").then(function(e){
				$scope.dictionarystaff = e
			})
		
		//经办人
			$scope.rrSubject={
						value:{
							diName:"请选择",
							diId:null
						}
					}
			//付款类型
			$scope.rrType={
						value:{
							diName:"请选择",
							diId:null
						}
					}
			//科目
			$scope.staffId={
						value:{
							diName:"请选择",
							diId:null
						}
					}		
	
		
	}
	$scope.selects()
	setTimeout(function (){
	if($stateParams.id!=''){
		$scope.isshows=true
		get.list('reimburse/findOne',{rrId:$stateParams.id}).then(function(e){
			$scope.pickertime=e.rrHandTime
		$scope.add={
		rrSubject:e.rrSubject,
		staffId:e.staffId,
		rrSummary:e.rrSummary,
		rrAcount:e.rrAcount,
		dateTime:e.rrHandTime, 
		rrType:e.rrType||'',
		projectName:null
		
	}
			
			//科目
	angular.forEach($scope.subjectDic,function(o){
		if(e.rrSubject==o.diId){
			$scope.rrSubject={
				value:o
			}
		}
	})
	//付款类型
	angular.forEach($scope.paymentDic,function(o){
		if(e.rrType==o.diId){
			$scope.rrType={
					value:o
			}
	
		}
	})
		//经办人
	angular.forEach($scope.dictionarystaff,function(o){
		if(e.staffId==o.diId){
			$scope.staffId={
				value:o
			}
		}
	})
		})
	}
	},200)
	
	$scope.add={
		rrSubject:null,
		staffId:null,
		rrSummary:'',
		rrAcount:null,
		dateTime:null,
		rrType:'',
		projectName:null
		
	}
	$scope.sub=function(val){
	
		$scope.add.dateTime=$scope.add.entryTime||$scope.add.dateTime
		if($scope.add.rrSubject!=null){
			$scope.add.rrSubject=$scope.add.rrSubject.diId||$scope.add.rrSubject
		}
		if($scope.add.rrType!=null){
			$scope.add.rrType=$scope.add.rrType.diId||$scope.add.rrType
		}
		if($scope.add.staffId!=null){
			$scope.add.staffId=$scope.add.staffId.diId||$scope.add.staffId
		}
		$scope.add.rrSubject=$scope.add.rrSubject||''
		$scope.add.staffId=$scope.add.staffId||''
		$scope.add.projectId=$scope.add.projectId||''
		if($stateParams.id!=''){
				$scope.add.rrId=$stateParams.id
				post.list("reimburse/update",$scope.add).then(function(o){
						$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
				})
			}else{
				post.list("reimburse/add",$scope.add).then(function(o){
						$state.go("home."+$stateParams.url,{page:$stateParams.page},{
						     		reload:true
						     	})
				})
				
			}
			
			
		
		
	}
	
})
